package shiyan2;

public class NextDate {

    public static String nextDate(int year, int month, int day){
        if(Math.round(month) != month || Math.round(day) != day || Math.round(year) != year){
            return "输入不是整数";
        }
        if(month<1 || month > 12)
            return "月不在1~12范围内";
        if(day < 1 || day > 31)
                return "天不在1~31范围内";
        if(year < 1900 || year > 2050)
            return "年不在1900~2050范围内";
        if(month == 12 && day == 31)
            return (year+1) + "年" + "1月" + "1日";
        int flag = 0;
        switch (month){
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                if(day == 31) {
                    flag = 1;
                    break;
                }
            case 4:
            case 6:
            case 9:
            case 11:
                if(day == 30){
                    flag = 1;
                    break;
                }
            case 2:
                //闰年
                if (year%4 == 0 && year%100 != 0) {
                    if (day > 29)
                        return "天不在范围内";
                    else if (day == 29) {
                        flag = 1;
                        break;
                    }
                }
                else {
                    if(day > 28)
                        return "天不在范围内";
                    else if(day == 28){
                        flag = 1;
                        break;
                    }
                }
        }
        if(flag == 1){
            month++;
            day = 1;
            return year + "年" + month + "月" + day + "日";
        }
        else {
            return year + "年" + month + "月" + (day+1) + "日";
        }
    }
}
